package IssueFuction;

import issue.Issue;
import issue.IssueList;

import java.util.Scanner;

public class Deltfunctions implements IFunctions{
    @Override
    public void work(IssueList issueList) {
        System.out.println("删除问题:");
        int currentSize=issueList.getUsedSize();
        for (int i = 0; i < currentSize; i++) {//先显示一遍所有问题
            Issue issue=issueList.getIssues(i);
            System.out.println(issue);
        }
        System.out.println("请输入你要删除的问题序号:");
        Scanner scanner=new Scanner(System.in);
        int chose=scanner.nextInt();//删除的问题序号
        int index=-1;//记录删除问题的下标
        for (int i = 0; i < currentSize; i++) {
            Issue tmp=issueList.getIssues(i);
            if(tmp.getNumber()==chose){
                index=i;
                break;
            }
        }
        for (int j = index; j < currentSize-1; j++) {
            Issue issue=issueList.getIssues(j+1);//获取当前下标的后一元素
            issue.setNumber(j+1);//把其序号变化
            issueList.setIssues(j,issue);//把后一元素放入
        }
        issueList.setUsedSize(currentSize-1);//删除了，数量减一
        issueList.setIssues(currentSize-1,null);//末尾置为空
        System.out.println("删除成功");
    }
}
